package com.zhs.smartmall.order.service.impl;


import com.zhs.smartmall.order.model.OmsOrderReturnReason;
import com.zhs.smartmall.order.dao.OmsOrderReturnReasonDao;
import com.zhs.smartmall.order.service.IOmsOrderReturnReasonService;
import com.zhs.smartmall.order.dto.OmsOrderReturnReasonDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author zhenghuisheng
 * @since 2023-11-12
 */
@Service
@Slf4j
public class OmsOrderReturnReasonServiceImpl extends ServiceImpl< OmsOrderReturnReasonDao, OmsOrderReturnReason> implements IOmsOrderReturnReasonService {

    @Resource
    private OmsOrderReturnReasonDao omsOrderReturnReasonDao;

    @Override
    @Transactional
    public R addOrUpdate(OmsOrderReturnReasonDto omsOrderReturnReasonDto) {
        if (BeanUtil.isEmpty(omsOrderReturnReasonDto)) throw new ServiceException("数据不能为空");
        OmsOrderReturnReason omsOrderReturnReason = new OmsOrderReturnReason();
        BeanUtil.copyProperties(omsOrderReturnReasonDto,omsOrderReturnReason);
        if (omsOrderReturnReasonDto.getId() == null){
            omsOrderReturnReasonDao.insert(omsOrderReturnReason);
            return R.ok("数据插入成功");
        }else {
            omsOrderReturnReasonDao.updateById(omsOrderReturnReason);
            return R.ok("数据更新成功");
        }
    }
}